package cc.rengu.igas.momp.common.util;

import cc.rengu.igas.momp.common.constant.CommonConstant;
import cc.rengu.oltp.utility.util.StringUtil;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * 金额工具方法
 *
 * @author liujinan
 * @since 2020/8/2 9:01
 */

public class MompAmountUtil {

    /**
     * String类型金额保留两位小数,四舍五入
     *
     * @param amount 待格式化金额
     * @return resultAmount 返回码
     * @author liujinan
     * @date 2020/8/2 9:53
     */
    public static String getTwoDecimal(String amount) {
        if (StringUtil.isEmptyOrNull(amount)) {
            return null;
        }
        amount = amount.trim();
        DecimalFormat format = new DecimalFormat(CommonConstant.ZERO_AMOUNT);
        String resultAmout = format.format(new BigDecimal(amount));
        return resultAmout;
    }

    /**
     * String类型金额保留三位小数,四舍五入
     *
     * @param amount 待格式化金额
     * @return resultAmount 返回码
     * @author liujinan
     * @date 2020/8/2 9:53
     */
    public static String getThreeDecimal(String amount) {
        if (StringUtil.isEmptyOrNull(amount)) {
            return null;
        }
        DecimalFormat format = new DecimalFormat(CommonConstant.ZERO_AMOUNT);
        String resultAmout = format.format(new BigDecimal(amount));
        return resultAmout;
    }

    /**
     * String类型金额不保留小数,四舍五入
     *
     * @param amount 待格式化金额
     * @return resultAmount 返回码
     * @author liujinan
     * @date 2020/8/2 9:53
     */
    public static String getZeroDecimal(String amount) {
        if (StringUtil.isEmptyOrNull(amount)) {
            return null;
        }
        DecimalFormat format = new DecimalFormat(CommonConstant.ZERO_COMMON_CONSTANT);
        String resultAmout = format.format(new BigDecimal(amount));
        return resultAmout;
    }

}
